package com.daichi.yygh.user.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.daichi.yygh.common.result.Result;
import com.daichi.yygh.model.user.UserInfo;
import com.daichi.yygh.user.service.UserInfoService;
import com.daichi.yygh.vo.user.UserInfoQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@Api(tags = "后台管理用户认证")
@RestController
@RequestMapping("/admin/user")
public class UserController {

    private final UserInfoService userInfoService;

    @Autowired
    public UserController(UserInfoService userInfoService) {
        this.userInfoService = userInfoService;
    }

    @ApiOperation(value = "分页查询用户信息")
    @GetMapping("/{current}/{limit}")
    public Result list(@PathVariable Long current,
                       @PathVariable Long limit,
                       UserInfoQueryVo userInfoQueryVo) {
        Page<UserInfo> page = new Page<>(current, limit);
        Page<UserInfo> userInfoPage = userInfoService.getPageList(page, userInfoQueryVo);
        return Result.ok(userInfoPage);
    }

    @ApiOperation(value = "锁定和解锁用户")
    @GetMapping("lock/{userId}/{status}")
    public Result lock(@PathVariable Long userId, @PathVariable Integer status) {
        userInfoService.lock(userId, status);
        return Result.ok();
    }

    @ApiOperation(value = "查看用户详情")
    @GetMapping("/show/{userId}")
    public Result show(@PathVariable Long userId) {
        Map<String,Object> map = userInfoService.show(userId);
        return Result.ok(map);
    }

    @ApiOperation(value = "认证用户")
    @GetMapping("approval/{userId}/{authStatus}")
    public Result approval(@PathVariable Long userId, @PathVariable Integer authStatus) {
        userInfoService.approval(userId, authStatus);
        return Result.ok();
    }

}
